package com.tywj.navigation.city

import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.tywj.lib.core.common.util.ResourcesUtil
import com.tywj.lib.core.widget.recycleview.adapter.BaseViewHolder
import com.tywj.navigation.R
import com.tywj.navigation.entity.CityEntity
import com.tywj.panda.customer.common.widget.recyclerview.MyBaseAdapter

/**
 * 选择城市列表适配器
 */
class CityAdapter : MyBaseAdapter<CityEntity>(R.layout.navigation_city_recyclerview_item) {

    override fun convert(helper: BaseViewHolder, item: CityEntity) {
        super.convert(helper, item)
        helper.setText(R.id.tvCity, item.cityName)
    }

    override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
        super.onAttachedToRecyclerView(recyclerView)
        recyclerView.addItemDecoration(object : RecyclerView.ItemDecoration() {
            override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {

                val position = parent.getChildLayoutPosition(view)
                if (position != RecyclerView.NO_POSITION) {
                    when (position) {
                        // 第一个
                        0 -> {
                            outRect.top = ResourcesUtil.getDimensionPixelSize(R.dimen.dp_10)
                        }
                    }
                }
            }
        })
    }
}